package com.qzdsoft.erpcloud.service.basic.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.qzdsoft.erpcloud.domain.basic.Currency;
import com.qzdsoft.erpcloud.mapper.basic.CurrencyMapper;
import com.qzdsoft.erpcloud.service.basic.CurrencyService;
import com.qzdsoft.erpcloud.vo.query.basic.CurrencyInfo;
import com.qzdsoft.vo.LayTableResponse;
import com.qzdsoft.vo.Response;
import com.qzdsoft.vo.ResultEnum;

/**
 * Created by Admin
 */
@Service
public class BasicCurrencyServiceImpl implements CurrencyService {

    @Autowired
    private CurrencyMapper basicCurrencyMapper;

    @Override
    public Currency selectById(Integer id) {
        return basicCurrencyMapper.selectByPrimaryKey(id);
    }

    @Override
    public Response<String> saveOrUpd(Integer id, Integer company_id, String name, String decode, String symbol, Integer is_main, Integer is_preinstall, Integer exchang_rate_type, Float exchang_rate, Float max_translate, Integer translate_type, String remark) {
        if(null != id){
            Currency basicCurrency = new Currency(id, company_id, decode, symbol, is_main, is_preinstall, exchang_rate_type, exchang_rate, max_translate, translate_type, null, remark, name);
            basicCurrencyMapper.updateByPrimaryKey(basicCurrency);
            return new Response<String>(ResultEnum.SUCCESS);
        } else {
            basicCurrencyMapper.insert(new Currency(null, company_id, decode, symbol, is_main, is_preinstall, exchang_rate_type, exchang_rate, max_translate, translate_type, new Date(), remark, name));
            return new Response<String>(ResultEnum.SUCCESS);
        }

    }

    @Override
    public Response<String> del(Integer id) {
        /*BasicCurrency basicCurrency = selectById(id);
        basicCurrencyMapper.updateByPrimaryKey(basicCurrency);*/
        basicCurrencyMapper.deleteByPrimaryKey(id);
        return new Response<String>(ResultEnum.SUCCESS);
    }


    @Override
    public LayTableResponse<CurrencyInfo> selectData(String name, Integer companyId, Integer isPreinstall, Integer exchangRateType, Integer translateType, Integer start, Integer pageSize) {
        PageHelper.startPage(start, pageSize);
        List<CurrencyInfo> list = basicCurrencyMapper.selectData(name, companyId, isPreinstall, exchangRateType, translateType, start, pageSize);
        return new LayTableResponse<CurrencyInfo>(list);
    }

	@Override
	public List<Currency> selectAll(Integer companyId) {
		return basicCurrencyMapper.selectByCompanyId(companyId);
	}
    
    
}
